﻿using Alta.Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Camera
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private bool _alert=false;
        public bool Alert
        {
            get
            {
                return this._alert;
            }
            set
            {
                this._alert = value;
                if (this._alert)
                    this.runAnimation();
                else
                    App.alert = false;
            }
        }

        public MainWindow()
        {
            InitializeComponent();
            this.Top = App.setting.top;
            this.Left = App.setting.left;
            this.Alert = App.alert;
        }

        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            if(e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
                App.setting.top = this.Top;
                App.setting.left = this.Left;
            }
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void runAnimation()
        {
            ColorAnimation animation = new ColorAnimation();
            animation.From = Colors.Blue;
            animation.To = Colors.OrangeRed;
            animation.AutoReverse = true;
            PowerEase e = new PowerEase() { Power = 3, EasingMode = EasingMode.EaseInOut };
            animation.Duration = TimeSpan.FromSeconds(0.5);
            animation.EasingFunction = e;
            animation.Completed +=(s,o)=>
            {
                if(this._alert)
                    this.Color_UIIcon.BeginAnimation(SolidColorBrush.ColorProperty, animation);
            };
            this.Color_UIIcon.BeginAnimation(SolidColorBrush.ColorProperty, animation);

        }

        private void OffAlert_Click(object sender, RoutedEventArgs e)
        {
            this.Alert = false;
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                switch (e.Key)
                {
                    case Key.H:
                        this.Close();
                        break;
                    case Key.D:
                        this.Alert = false;
                        break;
                }
            }
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            setting.write(App.setting, App.fileSetting);
        }
    }
}
